<template>
  <div>
    <div>
      <el-table
        :data="tableData"
        style="width: 100%; margin-bottom: 20px"
        row-key="id"
        border
        default-expand-all
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column prop="IP" label="节点IP" sortable width="180">
        </el-table-column>
        <el-table-column prop="Role" label="身份" sortable width="180">
        </el-table-column>
        <el-table-column prop="miner_addr" label="地址" sortable width="180">
        </el-table-column>
        <el-table-column prop="CID" label="扇区ID"> </el-table-column>
        <el-table-column prop="sector_number" label="扇区编号">
        </el-table-column>
        <el-table-column prop="proof" label="扇区证明"> </el-table-column>
      </el-table>
    </div>
    <div>
      <el-button type="primary" @click="batch_prove"
        >扇区证明<i class="el-icon-s-flag el-icon--right"></i
      ></el-button>
      <el-button type="primary"
        >扇区转移<i class="el-icon-upload2 el-icon--right"></i
      ></el-button>
      <el-button type="primary"
        >扇区回收<i class="el-icon-download el-icon--right"></i
      ></el-button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  mounted() {
    axios
      .get("http://127.0.0.1:5000/nodes_sectors", {
        headers: {
          "Access-Control-Allow-Origin": "*",
          "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS",
        },
      })
      .then((response) => {
        var data = response.data;
        console.log(data);
        this.tableData = this.tableData.concat(data);
      });
  },
  methods: {
    // load(tree, treeNode, resolve) {
    //   setTimeout(() => {
    //     resolve([
    //       {
    //         id: 31,
    //         date: '2016-05-01',
    //         name: '王小虎',
    //         address: '上海市普陀区金沙江路 1519 弄'
    //       }, {
    //         id: 32,
    //         date: '2016-05-01',
    //         name: '王小虎',
    //         address: '上海市普陀区金沙江路 1519 弄'
    //       }
    //     ])
    //   }, 1000)
    // }
    batch_prove() {
      console.log("batch prove");
      var data = [
        {
          "storage-dir": "/home/zdw/.lotus-bench/bench",
          "sector-size": "2KiB",
          "miner-addr": "t01000",
          challenge: "gGOsfuBrIEwCqiAcPMZ1TavYN7bzy53n",
          "sector-number": "1",
        },
        {
          "storage-dir": "/home/zdw/.lotus-bench/bench",
          "sector-size": "2KiB",
          "miner-addr": "t01000",
          challenge: "gGOsfuBrIEwCqiAcPMZ1TavYN7bzy53n",
          "sector-number": "2",
        },
        {
          "storage-dir": "/home/zdw/.lotus-bench/bench",
          "sector-size": "2KiB",
          "miner-addr": "t01000",
          challenge: "gGOsfuBrIEwCqiAcPMZ1TavYN7bzy53n",
          "sector-number": "3",
        },
        {
          "storage-dir": "/home/zdw/.lotus-bench/bench",
          "sector-size": "2KiB",
          "miner-addr": "t01000",
          challenge: "gGOsfuBrIEwCqiAcPMZ1TavYN7bzy53n",
          "sector-number": "4",
        },
      ];
      axios.post("http://127.0.0.1:5000/batch/prove", data).then((response) => {
        var data = response.data;
        console.log(data);
        // this.tableData = this.tableData.concat(data);
      });
    },
  },
};
</script>

<style>
</style>
